﻿using hoemwork;
using NUnit.Framework;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;

namespace work
{
    public class DLinkTest:IEnumerable
    {
        //继续完成双向链表的测试和开发，实现：
        //node3.InsertAfter(node1); 场景
        //InerstBefore()：在某个节点前插入
        //Delete()：删除某个节点
        //[选] Swap()：交互某两个节点
        //[选] FindBy()：根据节点值查找到某个节点


        //让之前的双向链表，能够：被foreach迭代


 
        [Test]
        public void AddAfterTest()
        {
           
            DLink node1 = new DLink { Value = 1 };
            DLink node2 = new DLink { Value = 2 };
            DLink node3 = new DLink { Value = 3 };
            DLink node4 = new DLink { Value = 4 };
           
            //1 [2]
            node1.AddAfter(node2);
            Assert.IsNull(node1.Previous);
            Assert.AreEqual(node2, node1.Next);
            Assert.AreEqual(node1, node2.Previous);
            Assert.IsNull(node2.Next);
            //12[3]
            node2.AddAfter(node3);
            Assert.IsNull(node3.Next);
            Assert.AreEqual(node3, node2.Next);
            Assert.AreEqual(node2, node3.Previous);

            //12[4]3
            node2.AddAfter(node4);
            node3.Previous = node4;
            node4.Next = node3;
            node2.Next = node4;
            node4.Previous = node2;
            Assert.IsNull(node3.Next);
            Assert.AreEqual(node4, node2.Next);
            Assert.AreEqual(node2, node4.Previous);
            Assert.AreEqual(node3, node4.Next);
            Assert.AreEqual(node4, node3.Previous);
            Assert.IsNull(node3.Next);
            DLink node5 = new DLink { Value = 5 };
            DLink node6 = new DLink { Value = 6 };

            //124[5]3
            node3.AddBefore(node5);
            Assert.IsNull(node3.Next);
            Assert.AreEqual(node5, node3.Previous);
            Assert.AreEqual(node3, node5.Next);
            Assert.AreEqual(node4, node5.Previous);
            Assert.AreEqual(node5, node4.Next);
            //[6]124[5]3
            node1.AddBefore(node6);
            Assert.IsNull(node6.Previous);
            Assert.AreEqual(node6, node1.Previous);
            Assert.AreEqual(node1, node6.Next);
            //1 2 4 [5] 3(Delete)
            DLink.Delete(node5);
            Assert.AreEqual(node4, node3.Previous);
            Assert.AreEqual(node3, node4.Next);
            Assert.IsNull(node5.Previous);
            Assert.IsNull(node5.Next);
            //[1] 2 4  3(Delete)
            DLink.Delete(node1);
            Assert.AreEqual(node2, node4.Previous);
            Assert.AreEqual(node4, node2.Next);
            Assert.IsNull(node1.Previous);
            Assert.IsNull(node1.Next);
            // 2 4 [3](Delete)
            DLink.Delete(node3);
            Assert.IsNull(node3.Next);
            Assert.AreEqual(node2, node4.Previous);
            Assert.AreEqual(node4, node2.Next);
            Assert.IsNull(node3.Previous);
            Assert.IsNull(node3.Next);
        }

        public IEnumerator GetEnumerator()
        {
            return new MyClass();
       
        }


        class MyClass : IEnumerator
        {
            public object Current => throw new NotImplementedException();

            public bool MoveNext()
            {
                throw new NotImplementedException();
            }

            public void Reset()
            {
                throw new NotImplementedException();
            }
        }
    }
}




































